package com.itheima.blog.admin.controller;


import com.itheima.blog.admin.dto.PageDto;
import com.itheima.blog.admin.domain.po.TBanner;
import com.itheima.blog.admin.service.ITBannerService;
import com.itheima.blog.admin.vo.PageVO;
import com.itheima.blog.admin.vo.Result;
import com.itheima.common.domain.R;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import com.itheima.common.domain.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;

/**
 * <p>
 * 轮播图设置表 前端控制器
 * </p>
 *
 * @author hyf
 * @since 2023-07-12
 */
@RestController
@RequestMapping("/admin/banner")
@RequiredArgsConstructor
public class TBannerController {


    private final ITBannerService itBannerService;
    @PostMapping("/upload")
    @ApiOperation("上传图片")
    public R uploadFile (MultipartFile file) throws Exception{
        return itBannerService.uploadFile(file);
    }

    @DeleteMapping
    @ApiOperation("（批量）删除")
    public void deleteFile(@RequestParam List<Integer> ids){
        itBannerService.deleteFile(ids);
    }

    @PostMapping
    @ApiOperation("剪裁(编辑图片，替换）")
    public Result updateFile(@Param("file") MultipartFile file,@Param("id") Integer id) throws Exception{
        return itBannerService.updateFile(file,id);
    }

    @PostMapping("/list")
    @ApiOperation("列表展示")
    public PageVO<TBanner> selectALL(@RequestBody PageDto pageDto){
        return itBannerService.selectAll(pageDto);
    }
    @PostMapping("/all")
    public List<TBanner> findAll(){
        return itBannerService.list();
    }
}
